package org.za.communication.message;

import java.nio.charset.Charset;

import org.apache.http.message.BasicTokenIterator;
import org.apache.mina.core.buffer.IoBuffer;

import com.navi168.fwq21.util.Tools;

public class WhereGoMessage extends BaseMessage{
	private byte[] key = new byte[4];
	private String sender;//发送者
	private String receiver;//接收者
	private String atitle;//地址简称
	private String asnippet;//地址
	private String remarks;//备注
	private int lat;//维度
	private int log;//经度
		
	
	public byte[] getKey() {
		return key;
	}

	public void setKey(byte[] key) {
		this.key = key;
	}

	public String getSender() {
		return sender;
	}

	public void setSender(String sender) {
		this.sender = sender;
	}

	public String getReceiver() {
		return receiver;
	}

	public void setReceiver(String receiver) {
		this.receiver = receiver;
	}

	public String getAtitle() {
		return atitle;
	}

	public void setAtitle(String atitle) {
		this.atitle = atitle;
	}

	public String getAsnippet() {
		return asnippet;
	}

	public void setAsnippet(String asnippet) {
		this.asnippet = asnippet;
	}

	public String getRemarks() {
		return remarks;
	}

	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

	public int getLat() {
		return lat;
	}

	public void setLat(int lat) {
		this.lat = lat;
	}

	public int getLog() {
		return log;
	}

	public void setLog(int log) {
		this.log = log;
	}

	public WhereGoMessage() {
		super();
		this.msgId = 0x05;
	}

	@Override
	public IoBuffer getData() {
		try {
			buf = IoBuffer.allocate(2).setAutoExpand(true);
			buf.putUnsignedShort(this.getMsgId());
			buf.put(key);
			buf.putString(sender, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(receiver, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(atitle, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(asnippet, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			buf.putString(remarks, Charset.forName("utf-8").newEncoder());
			buf.put(new byte[1]);
			double lati = lat / 1E6;
			double longi = log / 1E6;
			buf.put(new Tools().getDegreeBytes(lati));
			buf.put(new Tools().getDegreeBytes(longi));
			buf.flip();
			return buf;
		} catch (Exception ee) {
			return null;
		}

	}

	@Override
	public void setData(IoBuffer buf) {
		// TODO Auto-generated method stub
		
	}

}
